package com.rong.DAO;

import com.rong.hibernate.BaseHibernateDAO;
import java.util.List;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.LockMode;
import org.hibernate.Query;
import org.hibernate.criterion.Example;
import com.rong.ORM.ZynMenu;

/**
 * A data access object (DAO) providing persistence and search support for
 * ZynMenu entities. Transaction control of the save(), update() and delete()
 * operations can directly support Spring container-managed transactions or they
 * can be augmented to handle user-managed Spring transactions. Each of these
 * methods provides additional information for how to configure it for the
 * desired type of transaction control.
 * 
 * @see com.rong.DAO.ZynMenu
 * @author MyEclipse Persistence Tools
 */

public class ZynMenuDAO extends BaseHibernateDAO {
	private static final Log log = LogFactory.getLog(ZynMenuDAO.class);
	// property constants
	public static final String MENU_NAME = "menuName";
	public static final String MENU_NAME_ZH = "menuNameZh";
	public static final String REMARK = "remark";
	public static final String EXTATTR1 = "extattr1";
	public static final String EXTATTR2 = "extattr2";
	public static final String EXTATTR3 = "extattr3";
	public static final String EXTATTR4 = "extattr4";
	public static final String EXTATTR5 = "extattr5";
	public static final String EXTATTR_DB1 = "extattrDb1";
	public static final String EXTATTR_DB2 = "extattrDb2";
	public static final String EXTATTR_DB3 = "extattrDb3";

//	public void save(ZynMenu transientInstance) {
//		log.debug("saving ZynMenu instance");
//		try {
//			getSession().save(transientInstance);
//			log.debug("save successful");
//		} catch (RuntimeException re) {
//			log.error("save failed", re);
//			throw re;
//		}
//	}
//
//	public void delete(ZynMenu persistentInstance) {
//		log.debug("deleting ZynMenu instance");
//		try {
//			getSession().delete(persistentInstance);
//			log.debug("delete successful");
//		} catch (RuntimeException re) {
//			log.error("delete failed", re);
//			throw re;
//		}
//	}

	public ZynMenu findById(java.lang.Integer id) {
		log.debug("getting ZynMenu instance with id: " + id);
		try {
			ZynMenu instance = (ZynMenu) getSession().get(
					ZynMenu.class, id);
			return instance;
		} catch (RuntimeException re) {
			log.error("get failed", re);
			throw re;
		}
	}

	public List findByExample(ZynMenu instance) {
		log.debug("finding ZynMenu instance by example");
		try {
			List results = getSession().createCriteria("com.rong.DAO.ZynMenu")
					.add(Example.create(instance)).list();
			log.debug("find by example successful, result size: "
					+ results.size());
			return results;
		} catch (RuntimeException re) {
			log.error("find by example failed", re);
			throw re;
		}
	}

	public List findByProperty(String propertyName, Object value) {
		log.debug("finding ZynMenu instance with property: " + propertyName
				+ ", value: " + value);
		try {
			String queryString = "from ZynMenu as model where model."
					+ propertyName + "= ?";
			Query queryObject = getSession().createQuery(queryString);
			queryObject.setParameter(0, value);
			return queryObject.list();
		} catch (RuntimeException re) {
			log.error("find by property name failed", re);
			throw re;
		}
	}

	public List findByMenuName(Object menuName) {
		return findByProperty(MENU_NAME, menuName);
	}

	public List findByMenuNameZh(Object menuNameZh) {
		return findByProperty(MENU_NAME_ZH, menuNameZh);
	}

	public List findByRemark(Object remark) {
		return findByProperty(REMARK, remark);
	}

	public List findByExtattr1(Object extattr1) {
		return findByProperty(EXTATTR1, extattr1);
	}

	public List findByExtattr2(Object extattr2) {
		return findByProperty(EXTATTR2, extattr2);
	}

	public List findByExtattr3(Object extattr3) {
		return findByProperty(EXTATTR3, extattr3);
	}

	public List findByExtattr4(Object extattr4) {
		return findByProperty(EXTATTR4, extattr4);
	}

	public List findByExtattr5(Object extattr5) {
		return findByProperty(EXTATTR5, extattr5);
	}

	public List findByExtattrDb1(Object extattrDb1) {
		return findByProperty(EXTATTR_DB1, extattrDb1);
	}

	public List findByExtattrDb2(Object extattrDb2) {
		return findByProperty(EXTATTR_DB2, extattrDb2);
	}

	public List findByExtattrDb3(Object extattrDb3) {
		return findByProperty(EXTATTR_DB3, extattrDb3);
	}

	public List findAll() {
		log.debug("finding all ZynMenu instances");
		try {
			String queryString = "from ZynMenu";
			Query queryObject = getSession().createQuery(queryString);
			return queryObject.list();
		} catch (RuntimeException re) {
			log.error("find all failed", re);
			throw re;
		}
	}

	public ZynMenu merge(ZynMenu detachedInstance) {
		log.debug("merging ZynMenu instance");
		try {
			ZynMenu result = (ZynMenu) getSession().merge(detachedInstance);
			log.debug("merge successful");
			return result;
		} catch (RuntimeException re) {
			log.error("merge failed", re);
			throw re;
		}
	}

	public void attachDirty(ZynMenu instance) {
		log.debug("attaching dirty ZynMenu instance");
		try {
			getSession().saveOrUpdate(instance);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public void attachClean(ZynMenu instance) {
		log.debug("attaching clean ZynMenu instance");
		try {
			getSession().lock(instance, LockMode.NONE);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}
}